/**
 * 
 */
package com.nwpusp.display.resmgr;

import com.nwpusp.display.views.components.Animal;
import com.nwpusp.display.views.components.HurdleLeft;
import com.nwpusp.display.views.components.HurdleRight;
import com.nwpusp.display.views.components.Props;

import android.content.Context;
import android.util.Log;
import android.view.View;

/**
 * @author JustinCao
 *
 */
public class BarrierViewResManager extends ViewResourceManager {

	public enum BarrierType {left, right};
	
	@Override
	protected View allocView(Object[] param) {
		Context contextView = (Context) param[0];
		Float height = (Float) param[1];
		BarrierViewResManager.BarrierType type = (BarrierViewResManager.BarrierType)param[2];
		if(type == BarrierType.left) {
			return new HurdleLeft(contextView, height.floatValue());
		}
		else if(type == BarrierType.right) {
			return new HurdleRight(contextView, height.floatValue());
		}
		return null;
	}

	@Override
	protected View searchView(Object[] param) {
		BarrierViewResManager.BarrierType type = (BarrierViewResManager.BarrierType)param[2];
		if(isEmpty())
			return null;
		
		Object target = null;
		if(type == BarrierType.left) {
			for(Object obj : this) {
				if(obj instanceof HurdleLeft) {
					target = obj;
					this.remove(target);
					break;
				}
				else {
					target = null;
				}
			}
		}
		else if(type == BarrierType.right) {
			for(Object obj : this) {
				if(obj instanceof HurdleRight) {
					target = obj;
					this.remove(target);
					break;
				}
				else {
					target = null;
				}
			}
		}
		return (View) target;
	}
}
